package gaml.testing;

import gaml.core.GamlConfig;
import gaml.error.GamlException;
import gaml.text.TextNodeBridge;
import gaml.text.YamlNodePrinter;
import gaml.text.YamlPrinterStore;
import gaml.text.YamlText;
import gaml.text.printer.MappingNodePrinter;
import gaml.text.printer.ScalarNodePrinter;
import gaml.text.printer.SequenceNodePrinter;
import gaml.yaml.MappingNode;
import gaml.yaml.ScalarNode;
import gaml.yaml.SequenceNode;
import gaml.yaml.ahchor.YamlAnchor;

import org.junit.Test;


public class MappingNodePrinterTest {

	@Test
	public void testPrint () throws GamlException {
		MappingNode node = new MappingNode (null);
		
		node.setTag ("maptag");
		node.setAnchor (new YamlAnchor ("mapanch", node));
		node.setComment ("mapping node comment");
		
		SequenceNode seqnode = new SequenceNode (node);
		seqnode.addChild (new ScalarNode (seqnode).setValue ("seqval1"));
		seqnode.addChild (new ScalarNode (seqnode).setValue ("seqval2"));
		
		node.getMappingChildren ().put (new ScalarNode (node).setValue ("mapkey1"), new ScalarNode (node).setValue ("mapval1"));
		node.getMappingChildren ().put (new ScalarNode (node).setValue ("mapkey2"), new ScalarNode (node).setValue ("mapval2"));
		node.getMappingChildren ().put (new ScalarNode (node).setValue ("mapkey3"), seqnode /*new ScalarNode (node).setValue ("mapval3")*/);
		node.getMappingChildren ().put (new ScalarNode (node).setValue ("mapkey4"), new ScalarNode (node).setValue ("mapval4"));
		
		YamlPrinterStore store = new YamlPrinterStore ((YamlNodePrinter) new ScalarNodePrinter (GamlConfig.getDefault ()));
		store.register (new MappingNodePrinter (store, GamlConfig.getDefault ()));
		store.register (new SequenceNodePrinter (store, GamlConfig.getDefault ()));
		
		System.out.println (new TextNodeBridge (new YamlText (), node).parseNode (store).getText ().getText ());
	}
}